require('./PageMyYeWu.less');
import { Link, Control , Route } from 'react-keeper'
import arrowjd from './../../assets/icon/箭头.png';
import { Page,Panel,Toast,PanelHeader,Flex,FlexItem } from 'react-weui/build/packages';
import AppHead  from  '../../components/common/Header';
import AppHeadYeWu  from  '../../components/common/HeaderYeWu';


class MyYeWu extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showToast: false,
      showLoading: false,
      toastTimer: null,
      loadingTimer: null,
      urlPath: '',
      urlDisplay:true,
      urlName: '',
    }
    this.showLoading = this.showLoading.bind(this);
    this.showToast = this.showToast.bind(this);
    this.setNavigationPath = this.setNavigationPath.bind(this);
    this.setUrlDisplay = this.setUrlDisplay.bind(this);
    this.setUrlName = this.setUrlName.bind(this);
    this.routerWillLeave = this.routerWillLeave.bind(this);
    this.doSomething = this.doSomething.bind(this);
  }

  render() {

    return (

        <div className="myyewu"  infiniteLoader={false} ptr={false} title="Toast" subTitle="弹出式提示"  spacing>
          <AppHeadYeWu url={this.state.urlPath} name={this.state.urlName}
                       onSetUrlDisplay={this.setUrlDisplay}  urlDisplay={this.state.urlDisplay}  />
           {/*<Toast icon="loading" show={this.state.showLoading}>Loading...</Toast>*/}
          <div>123 </div>

            {this.props.children }

      </div>

    );
  }

 setNavigationPath(obj) {

    this.setState({urlPath: obj});
  }

  setUrlDisplay(obj) {
    this.setState({urlDisplay: obj});
  }

  setUrlName(obj) {
    this.setState({urlName: obj});
  }

  doSomething(event) {
    event.preventDefault();
    console.log('doSomething called by child with value:');
  }

  showLoading() {
    this.setState({showLoading: true});

    this.state.loadingTimer = setTimeout(()=> {
      this.setState({showLoading: false});
    }, 2000);
  }

  showToast() {
    this.setState({showToast: true});

    this.state.toastTimer = setTimeout(()=> {
      this.setState({showToast: false});
    }, 2000);
  }

  componentWillMount() {
    this.showLoading();

  }

  notice() {

  }

  routerWillLeave(nextLocation) {
    if (!this.state.isSaved)
      return '确认要离开？';
  }

  componentDidMount() {

    this.setNavigationPath('/myyewu/rizhilist')
    if (Control.path.indexOf('rizhi') > 0)
    {
      this.setUrlName('日志');
    }else
    {
      if (Control.path.indexOf('qrhome') > 0)
      {
        this.setUrlName('二维码');
      }
      else
      {
        if (Control.path.indexOf('chufa') > 0)
        {
          this.setUrlName('通知书');
        }
        else
        {
          this.setUrlName('其它');
        }
      }

    }
  }

  componentWillReceiveProps(nextProps) {

    console.log(Control.path.indexOf('list'));
    if (Control.path.indexOf('list') > 0)
    {
      this.setUrlDisplay(false);
    }else
    {
      this.setUrlDisplay(true);
    }

  }


  shouldComponentUpdate(nextProps, nextState) {
    const thisProps = this.props || {},
      thisState = this.state || {};

    if (Object.keys(thisProps).length !== Object.keys(nextProps).length ||
      Object.keys(thisState).length !== Object.keys(nextState).length) {
      return true;
    }

    for (const key in nextProps) {
      if (thisProps[key] !== nextProps[key] ) {
        console.log(thisProps[key], nextProps[key]);
        return true;
      }
    }

    for (const key in nextState) {
      if (thisState[key] !== nextState[key] ) {
        return true;
      }
    }
    return false;
  }

  componentWillUpdate(nextProps, nextState) {


  }


  componentDidUpdate(prevProps, prevState) {



  }


  componentWillUnmount() {
    this.state.toastTimer && clearTimeout(this.state.toastTimer);
    this.state.loadingTimer && clearTimeout(this.state.loadingTimer);
    console.log('111111111');
  }

}



export default MyYeWu ;

